'use strict';

// 获取Controller类
const Controller = require('egg').Controller;

class RecordController extends Controller {
  async create() {
    const { ctx } = this;
    const { userId } = ctx.helper.jsonToHump(ctx.decode);
    const { actionType, extInfo } = ctx.request.body;
    const recordId = await ctx.service.record.create(userId, actionType, extInfo);
    ctx.body = ctx.helper.formatResponse({ recordId }, 200, '新增标签成功');
  }

  async index() {
    const { ctx } = this;
    const { userId } = ctx.helper.jsonToHump(ctx.decode);
    const { page, size, order } = ctx.request.query;
    const { list, total } = await ctx.service.record.index(userId, parseInt(page), parseInt(size), parseInt(order));
    ctx.body = ctx.helper.formatResponse({ list: ctx.helper.jsonToHump(list), total }, 200, '获取标签列表成功');
  }
}

module.exports = RecordController;
